//app.js
App({
  onLaunch: function () {
    var that = this
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    
    // 登录
    wx.login({
      success (res) {
        console.log(res.code);
        
        if (res.code) {
          //发起网络请求
          wx.request({
            url: that.globalData.url+'login/',
            data: {
              code: res.code
            },
            success:function(res){

              wx.setStorage({
                key:"userinfo",
                data:{
                  openid:res.data.openid,
                  nickname:res.data.nickname
                }
              })
            },
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })


  },


  globalData: {
    userInfo: null,
    url:"171.94.96.107/"
  }
})